package com.siss.tenancy.user.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.siss.tenancy.finals.SystemFinal;
import com.siss.tenancy.vo.SissPropertiesSysVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 类名: PropertiesSysRedisUtil.java
 * 描述: 系统配置属性获取缓存工具类
 * 创建人: yingw
 * 创建时间: 2018年10月11日下午4:27:11
 */
@Component
public class PropertiesSysRedisUtil {
	@Autowired
	private RedisTemplate redisTemplate;
	
	public  String getValue(String code) throws IOException{       
        HashOperations<String, Object, Object> ops = redisTemplate.opsForHash();
    	if(ops.hasKey(SystemFinal.REDIS_CACHE_KEY_PROPERTIESSYS, code)){ // 缓存命中
    	String json = ops.get(SystemFinal.REDIS_CACHE_KEY_PROPERTIESSYS,code).toString();
    	SissPropertiesSysVO vo = new SissPropertiesSysVO();
		ObjectMapper objectMapper = new ObjectMapper();
		vo = objectMapper.readValue(json, SissPropertiesSysVO.class);
		return vo.getSysValue();
    	}
    	return "";
	}
}
